﻿using Niti.OrderManage.OrderManage.ValueObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;

namespace Niti.OrderManage.OrderManage
{
   public class ReceiptOrderLineItem : Entity<int>
    {
        /// <summary>
        /// 入库订单编号
        /// </summary>
        public string ReceiptOrderCode { get; set; }
        /// <summary>
        /// 行号
        /// </summary>
        public int LineNumber { get; set; }
        #region 商品

        /// <summary>
        /// 商品唯一编号
        /// </summary>
        public string Commodity_Code { get; set; }
        /// <summary>
        /// 商品名称
        /// </summary>

        public string Commodity_CName { get; set; }
        /// <summary>
        /// 商品单价
        /// </summary>

        public float Commodity_CPrice { get; set; }
        #endregion
        /// <summary>
        /// 实际的产品价格
        /// </summary>
        public float RealityCPrice { get; set; }
        /// <summary>
        /// 预定数量
        /// </summary>
        public int Count { get; set; }
        /// <summary>
        /// 预定小计
        /// </summary>

        public float Subtotal { get; set; }
        /// <summary>
        /// 实际到货数量
        /// </summary>

        public int RealityCount { get; set; }
        /// <summary>
        /// 实际小计
        /// </summary>
        public float RealitySubtotal { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { get; set; } = DateTime.Now;
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? UpdateTime { get; set; }

        protected ReceiptOrderLineItem()
        {

        }

        public ReceiptOrderLineItem(string orderCode, int lineNumber, OrderLineItem_Commodity commodity, int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException(
                    "You can not add zero or negative count of commoditys!",
                    nameof(count)
                );
            }
            ReceiptOrderCode = orderCode;
            LineNumber = lineNumber;
            Commodity_Code = commodity.Code;
            Commodity_CName = commodity.CName;
            Commodity_CPrice = commodity.CPrice;
            RealityCPrice = commodity.CPrice;
            Count = count;
            Subtotal = commodity.CPrice * count;
            RealityCount = count;
            RealitySubtotal = commodity.CPrice * count;
        }

        internal void ChangeRealitySubtotal(float price, int newCount)
        {
            RealityCount = newCount;
            RealitySubtotal = price * newCount;
            RealityCPrice = price;
        }


    }
}
